part of 't3_map_controller.dart';

extension Polyline on T3MapController {
  /// 向地图添加线段
  T3Polyline addPolyline({required T3PolylineOptions options}) {
    final polyline = T3Polyline(options);
    _methodChannel.invokeMethod('polylines#add', jsonEncode(polyline.toJson()));
    _polylines.add(polyline);
    return polyline;
  }

  /// 更新指定线段，当前只支持更新坐标，样式暂不支持
  void updatePolyline({required T3Polyline polyline, required T3PolylineOptions newPolylineOptions}) {
    polyline.update(points: newPolylineOptions.points);
    _methodChannel.invokeMethod('polylines#update', jsonEncode(polyline.toJson()));
  }

  /// 移除对应的线段
  void removePolyline({required T3Polyline polyline}) {
    _methodChannel.invokeMethod('polylines#remove', jsonEncode(polyline.toJson()));
    _polylines.remove(polyline);
  }

  /// 在可视区域内显示Polyline
  void showPolylines({required List<T3Polyline> polylines, EdgeInsets edgeInsets = EdgeInsets.zero, required bool animated}) {
    final json = {"polylines": polylines.map((e) => e.toJson()).toList() ,"animated": animated, "edgeInsets": _edgeInsetsToJson(edgeInsets)};
    _methodChannel.invokeMethod('polylines#show', jsonEncode(json));
  }
}
